package com.zbu.system.controller.sysuser;

import com.zbu.common.core.comtroller.BaseController;
import com.zbu.common.core.constants.HttpConstants;
import com.zbu.common.core.domain.R;
import com.zbu.common.core.domain.vo.LoginUserVO;
import com.zbu.system.domain.sysuser.dto.LoginDTO;
import com.zbu.system.domain.sysuser.dto.SysUserSaveDTO;
import com.zbu.system.domain.sysuser.vo.SysUserVo;
import com.zbu.system.service.sysuser.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysUser")
@Tag(name="管理员用户API")
public class SysUserController extends BaseController {
    @Autowired
    private ISysUserService iSysUserService;
    @PostMapping("/login")
    @Operation(summary = "登录",description = "根据登录信息判断是否登录成功")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    public R<String> login(@RequestBody LoginDTO loginDTO){
            return iSysUserService.login(loginDTO);
    }
    //退出登录
    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION)String token){
       return toR(iSysUserService.logout(token));
    }
    @PostMapping("/add")
    @Operation(summary = "新增用户",description = "新增管理员账户")
    @ApiResponse(responseCode = "1000",description = "增加成功")
    public R<Void>add(@RequestBody SysUserSaveDTO sysUserSaveDTO){
        return toR(iSysUserService.add(sysUserSaveDTO));
    }
    @DeleteMapping("/delete")
    @Operation(summary = "删除用户",description = "删除管理员账户")
    @ApiResponse(responseCode = "1000",description = "删除成功")
    @Parameters(value = {
            @Parameter(name="userId",in = ParameterIn.PATH,description = "用户Id")
    })
    public R<Void>delete(@PathVariable Long userId){
        return null;
    }
    @Operation(summary = "用户详情",description = "查看账户详情")
    @ApiResponse(responseCode = "1000",description = "查看成功")
    @Parameters(value = {
            @Parameter(name="userId",in = ParameterIn.QUERY,description = "用户Id"),
            @Parameter(name="sex",in = ParameterIn.QUERY,description = "用户性别")
    })
    @PostMapping("/detail")
    public R<SysUserVo>detail(@RequestParam(required = true)Long userId, @RequestParam(required = false)String sex){
        return null;
    }
    @GetMapping("/d")
    public String d(){
        return "ok";
    }
    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return iSysUserService.info(token);
    }

}
